package com.j.lemon.learn.thread.NIO;

import java.io.*;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SimpleClient {
    public static final long time = 1000*1000*1000;
    public static void main(String[] args) {
        ExecutorService executorService= Executors.newCachedThreadPool();
        for(int i =0;i<1;i++){
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Socket socket = new Socket("localhost",8089);
                        OutputStream outputStream=socket.getOutputStream();
                        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
                        PrintWriter printWriter=new PrintWriter(outputStreamWriter,true);
                        Thread.sleep(6000);
                        printWriter.println("hello");

                        InputStream is = socket.getInputStream();
                        InputStreamReader isr = new InputStreamReader(is);
                        BufferedReader br = new BufferedReader(isr);
                        System.out.println("客户端说："+br.readLine());

                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {

                    }
                }
            });
        }

    }
}
